import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = '/product/product/list',
  save ='/product/product/add',
  edit ='/product/product/edit',
  deleteOne = '/product/product/delete',

  itemList = '/product/productItem/list',
  itemSave ='/product/productItem/add',
  itemEdit ='/product/productItem/edit',
  itemDel  = '/product/productItem/delete',
  itemTree = '/product/productItem/getByParentId',

  levelList = '/product/productLevel/list',
  levelSave ='/product/productLevel/add',
  levelEdit ='/product/productLevel/edit',
  levelDel  = '/product/productLevel/delete',
  levelSelect = '/product/productLevel/getLevelSelect',

  productTree = '/product/product/tree',

  customerSelect = '/customer/regeionSelect',
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({url: Api.list, params});

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate 是否是更新数据
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}


//资方产品 ===============================================================================
/**
 * 列表接口
 * @param params
 */
export const itemList = (params) =>
  defHttp.get({url: Api.itemList, params});

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const itemDel= (params,handleSuccess) => {
  return defHttp.delete({url: Api.itemDel, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate 是否是更新数据
 */
export const itemSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.itemEdit : Api.itemSave;
  return defHttp.post({url: url, params});
}

/**
 * 列表接口
 * @param params
 */
 export const itemTree = (params) => defHttp.get({url: Api.itemTree, params});

//客户等级 ===============================================================================
/**
 * 列表接口
 * @param params
 */
 export const levelList = (params) => defHttp.get({url: Api.levelList, params});

/**
* 删除单个
* @param params
* @param handleSuccess
*/
export const levelDel= (params,handleSuccess) => {
 return defHttp.delete({url: Api.levelDel, params}, {joinParamsToUrl: true}).then(() => {
   handleSuccess();
 });
}

/**
* 保存或者更新
* @param params
* @param isUpdate 是否是更新数据
*/
export const levelSaveOrUpdate = (params, isUpdate) => {
 let url = isUpdate ? Api.levelEdit : Api.levelSave;
 return defHttp.post({url: url, params});
}

/**
 * 客户等级下接列表
 * @param params
 */
 export const getLevelSelect = (params) => defHttp.get({url: Api.levelSelect, params});

/**
 * 客户等级下接列表
 * @param params
 */
 export const productTree = () => defHttp.get({url: Api.productTree}, {isTransformResponse:false});

 /**
 * 收支项目 - 支出树型
 * @param params
 */
export const customerSelect = () => defHttp.get({url: Api.customerSelect}, {isTransformResponse:false});